//
//  RootViewController.m
//  啊啊啊啊啊啊啊啊啊啊
//
//  Created by dllo on 15/11/16.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "RootViewController.h"
#import "HYCTableViewController.h"
@interface RootViewController ()
{
    UIPopoverController *popover;
}
@end

@implementation RootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createUI];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction:) name:@"changeColor" object:nil];
}

- (void)createUI{
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 750, 200)];
    
    label.text = @"哈哈哈哈啊哈哈哈哈哈哈";
    label.font = [UIFont systemFontOfSize:60];
    label.tag = 1000;
    [self.view addSubview:label];
    
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(250, 400, 200, 50);
    [button setTitle:@"改变" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(pressButton:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view addSubview:button];
    
}
- (void)pressButton:(UIButton *)button{
    //创建popoverController对象
    HYCTableViewController *hyc = [[HYCTableViewController alloc] init];
    popover = [[UIPopoverController alloc] initWithContentViewController:hyc];
    
    // 设置popoverController内容视图大小
    [popover setPopoverContentSize:CGSizeMake(200, .00) animated:YES];
    
    // 将popoverController显示出来
    [popover presentPopoverFromRect:CGRectMake(50, 0, 200, 100) inView:(UIButton *)button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

    
}

- (void)notificationAction:(NSNotification *)notif {
    NSString *str = notif.object;
    
    UILabel *label = (UILabel *)[self.view viewWithTag:1000];
    
    if ([str isEqualToString:@"red"]) {
        label.textColor = [UIColor redColor];
    }else if ([str isEqualToString:@"green"]) {
        label.textColor = [UIColor greenColor];
    }else {
        label.textColor = [UIColor yellowColor];
    }
    // 气泡消失
    [popover dismissPopoverAnimated:YES];
    
    
    
    
    
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
